#ifndef __STACK_H__
#define __STACK_H__

#include <assert.h>

template<class DType>
struct Stack {
	DType* elements;
	int top;
	int capacity;

	Stack(int capacity) :capacity(capacity), top(-1) {
		assert(capacity >= 0);
		elements = new DType[capacity];
	}
	~Stack() {
		delete[]elements;
	}

	bool isEmpty() { return top < 0; }
	bool isFull() { return top + 1 >= capacity; }
	bool push(const DType& data);
	DType pop();
};

template<class DType>
bool Stack<DType>::push(const DType& data) {
	if (top + 1 >= capacity)
		return false;
	elements[++top] = data;
	return true;
}

template<class DType>
DType Stack<DType>::pop() {
	if (top == -1) {
		exit(1);
	}
	return elements[top--];
}


#endif //__STACK_H__